package query.config;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import com.alibaba.druid.pool.DruidDataSource;

/**
 * 数据初始化类，代替<beans></beans>
 * 
 * @author lzy
 * @version 1.0.4
 *
 */
@Configuration
@ComponentScan({ "query.jdbc" })
public class DataConfig {

	/**
	 * 注入datasource
	 * 
	 * @return datasource
	 */
	@Bean
	public DataSource datasource() {
		DruidDataSource source = new DruidDataSource();
		source.setUrl("jdbc:mysql://localhost:3306/query?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC");
		source.setUsername("root");
		source.setPassword("123456");
		source.setDriverClassName("com.mysql.cj.jdbc.Driver");
		return (DataSource) source;
	}

	/**
	 * 注入jdbctemplate
	 * 
	 * @param dataSource 数据库设置
	 * @return jdbctemplate
	 */
	@Bean
	public JdbcTemplate jdbcTemplate(DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}
}
